﻿using ECG.Common;

namespace ECG.DAL
{
    public partial class CampaignCustomerDb 
    {
        /// <summary>
        /// Lấy về bản ghi theo email
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public static CampaignCustomerDto GetByEmail(string email)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_CampaignCustomer_GetByEmail");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@Email", email));
                return dao.GetSingleDTO<CampaignCustomerDto>(ref command);
            }
            finally
            {
                command.Connection.Close();
            }
        }

        /// <summary>
        /// Thêm mới bản ghi chứa dữ liệu khách hàng đăng ký nhận vé số
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Add(CampaignCustomerDto model)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_CampaignCustomer_Add");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@Name", model.Name));
                command.Parameters.Add(dao.CreateParameter("@Email", model.Email));
                command.Parameters.Add(dao.CreateParameter("@MobilePhone", model.MobilePhone));
                command.Parameters.Add(dao.CreateParameter("@Address", model.Address));
                command.Parameters.Add(dao.CreateParameter("@MaXoSo", model.MaXoSo));
                return command.ExecuteNonQuery();
            }
            finally
            {
                command.Connection.Close();
            }
        }
    }
}
